<?php

namespace api\controller;

// +----------------------------------------------------------------------
// | 属性数据控制层
// +----------------------------------------------------------------------

use common\controller\VerifyController;
use common\service\AttributeService;
use think\Request;

class AttributeController extends VerifyController
{
    /**
     * @var \common\service\AttributeService
     */
    protected $attributeService;

    public function _initialize()
    {
        $this->attributeService = new AttributeService();
    }

    /**
     * 属性删除
     * @param Request $request
     * @return \think\Response
     * @throws \think\Exception
     */
    public function delete(Request $request)
    {
        $param = $request->param();
        $res = $this->attributeService->deleteAttribute($param['param']['filter']);
        return json(success_response('', $res));
    }

    /**
     * 获取指定工序分类的属性列表
     * @param Request $request
     * @return \think\Response
     */
    public function getStepCategoryAttributes(Request $request)
    {
        $param = $request->param();
        $resData = $this->attributeService->getStepCategoryAttributes($param['param']['filter']);
        return json(success_response('', $resData));
    }

    /**
     * 获取属性列表
     * @param Request $request
     * @return \think\Response
     */
    public function getAttributeList(Request $request)
    {
        $resData = $this->attributeService->getAttributeList();
        return json(success_response('', $resData));
    }

    /**
     * 获取指定工序分类 属性树
     * @param Request $request
     * @return \think\Response
     */
    public function getAttributeTree(Request $request)
    {
        $param = $request->param();
        $resData = $this->attributeService->getAttributeTree($param['param']);
        return json(success_response('', $resData));
    }
}
